﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.ComponentModel;
using System.Reflection;
using Microsoft.Xna.Framework;

namespace FormaBedoboNS
{
    /// <summary>
    /// Felhasználó egyéni beállításai
    /// </summary>
    [Serializable]
    public class UserSettings
    {
        private static UserSettings _instance = null;


        /// <summary>
        /// példány létrehozása
        /// </summary>
        public static UserSettings instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new UserSettings();
                    
                }

                return _instance;
            }
        }
        /// <summary>
        /// ctor
        /// </summary>
        public UserSettings()
        {

        }

        /// <summary>
        /// adatok HDD-re írása
        /// </summary>
        public void adatKiiras()
        {
            try
            {
                XmlSerializer serializer;
                TextWriter WriteFileStream;
                //serializer = new XmlSerializer(typeof(UserSettings));
                serializer = XmlSerializer.FromTypes(new[] { typeof(UserSettings) })[0];
                WriteFileStream = new StreamWriter(AppSettings.instance.path + "UserSettings.xml", false);
                serializer.Serialize(WriteFileStream, _instance);
                WriteFileStream.Close();


            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }

        /// <summary>
        ///  HDD-ről adatok olvasása
        /// </summary>
        public void adatfelolvasas()
        {
            try
            {
                XmlSerializer serializer;
                TextReader ReadFileStream;
                //serializer = new XmlSerializer(typeof(UserSettings));
                serializer = XmlSerializer.FromTypes(new[] { typeof(UserSettings) })[0];
                ReadFileStream = new StreamReader(AppSettings.instance.path + "UserSettings.xml", false);
                _instance = (UserSettings)serializer.Deserialize(ReadFileStream);
                Console.WriteLine("Felhasználó beállítások beolvasása");
                ReadFileStream.Close();
            }
            catch (Exception)
            {
                Console.WriteLine("Nincs felhasználó beállítás...");
            }
        }

       

    }
}
